package com.yunhai.xc.test;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yunhai.xc.user.domain.UserInfo;
import com.yunhai.xc.user.persistence.UserInfoRepository;

@RestController
@RequestMapping("/mogo")
public class MongoDB {
	@Autowired
	private UserInfoRepository userInfoRepository;

	@RequestMapping("save")
	public String save() {
		UserInfo userInfo = new UserInfo();
		userInfo.setName("韩信");
		userInfo.setAge(20);
		userInfoRepository.save(userInfo);
		userInfo = new UserInfo();
		userInfo.setName("李白");
		userInfo.setAge(30);
		userInfoRepository.save(userInfo);
		return "ok";
	}

	@RequestMapping("find")
	public List<UserInfo> find() {
		return userInfoRepository.findAll();
	}

	@RequestMapping("findByName")
	public UserInfo findByName() {
		return userInfoRepository.findByName("张三");
	}

}
